import { defHttp } from '@/utils/http/axios';
import {
  IDraftListResult,
  IErrMsg,
  IPublishExpData,
  ITemplateListResult,
  IVersionPageListResult,
} from './type';

enum Api {
  draftList = '/admin/wx3rdVersion/getTemplateDraftList',
  addToTemplate = '/admin/wx3rdVersion/addToTemplate',
  versionPageList = '/admin/wx3rdVersion/selectVersionPageList',
  releaseVersionDown = '/admin/wx3rdVersion/selectReleaseVersionPageList',
  expVersionDown = '/admin/wx3rdVersion/selectExpVersionPageList',
  publishExp = '/admin/wx3rdVersion/publishExp',
  templateList = '/admin/wx3rdVersion/getTemplateList',
  submitAudit = '/admin/wx3rdVersion/submitAudit',
  trialQRCode = '/admin/wx3rdVersion/getTrialQRCode',
  releaseOnline = '/admin/wx3rdVersion/release',
  historyVersion = '/admin/wx3rdVersion/getHistoryVersion',
  revertCodeRelease = '/admin/wx3rdVersion/revertCodeRelease',
  recordPageList = '/admin/wx3rdVersion/selectRecordPageList',
  recordVersionDown = '/admin/wx3rdVersion/selectVersionList',
  deleteTemplate = '/admin/wx3rdVersion/deleteTemplate',
}

/**
 * @description 草稿箱列表
 * @date 13/07/2022
 * @export
 * @param
 */
export function draftList() {
  return defHttp.get<IDraftListResult>({
    url: Api.draftList,
  });
}

/**
 * @description 将草稿添加到模板库
 * @date 13/07/2022
 * @export
 * @param
 */
export function addToTemplate(id, type) {
  return defHttp.get({
    url: Api.addToTemplate + `/${id}?templateType=${type}`,
  });
}

/**
 * @description 获取发版管理列表
 * @date 13/07/2022
 * @export
 * @param
 */
export function versionPageList(params) {
  return defHttp.get<IVersionPageListResult>({
    url: Api.versionPageList,
    params,
  });
}

/**
 * @description 获取正式版版本(下拉框)
 * @date 13/07/2022
 * @export
 * @param
 */
export function releaseVersionDown() {
  return defHttp.get({
    url: Api.releaseVersionDown,
  });
}

/**
 * @description 获取体验版版本(下拉框)
 * @date 13/07/2022
 * @export
 * @param
 */
export function expVersionDown() {
  return defHttp.get({
    url: Api.expVersionDown,
  });
}

/**
 * @description 发布体验版
 * @date 13/07/2022
 * @export
 * @param
 */
export function publishExp(data: IPublishExpData) {
  return defHttp.post<IErrMsg[]>({
    url: Api.publishExp,
    data,
  });
}

/**
 * @description 获取模板列表
 * @date 13/07/2022
 * @export
 * @param
 */
export function templateList(params) {
  return defHttp.get<ITemplateListResult[]>({
    url: Api.templateList,
    params,
  });
}

/**
 * @description 模板删除
 * @date 13/07/2022
 * @export
 * @param
 */
export function deleteTemplate(data) {
  return defHttp.post({
    url: Api.deleteTemplate,
    data,
  });
}

/**
 * @description 提交审核
 * @date 13/07/2022
 * @export
 * @param
 */
export function submitAudit(data: IPublishExpData) {
  return defHttp.post<IErrMsg[]>({
    url: Api.submitAudit,
    data,
  });
}

/**
 * @description 预览体验版(图片url)
 * @date 13/07/2022
 * @export
 * @param
 */
export function trialQRCode(tenantId) {
  return defHttp.get({
    url: Api.trialQRCode,
    params: { tenantId },
  });
}

/**
 * @description 发布线上
 * @date 13/07/2022
 * @export
 * @param
 */
export function releaseOnline(data) {
  return defHttp.post({
    url: Api.releaseOnline,
    data,
  });
}

/**
 * @description 获取小程序可回退版本
 * @date 13/07/2022
 * @export
 * @param
 */
export function historyVersion(params) {
  return defHttp.get({
    url: Api.historyVersion,
    params,
  });
}

/**
 * @description 回滚
 * @date 13/07/2022
 * @export
 * @param
 */
export function revertCodeRelease(data: IPublishExpData) {
  return defHttp.post({
    url: Api.revertCodeRelease,
    data,
  });
}

/**
 * @description 获取发版记录列表
 * @date 13/07/2022
 * @export
 * @param
 */
export function recordPageList(params) {
  return defHttp.get({
    url: Api.recordPageList,
    params,
  });
}

/**
 * @description 获取版本号下拉框
 * @date 13/07/2022
 * @export
 * @param
 */
export function recordVersionDown() {
  return defHttp.get({
    url: Api.recordVersionDown,
  });
}
